import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import UserLayout from '@/layouts/UserLayout.vue'
import BasicLayout from '@/layouts/BasicLayout.vue'
import EmptyRouteView from '@/layouts/EmptyRouteView.vue'
import HomeLayout from '@/layouts/HomeLayout.vue'
import RouteView from '@/layouts/RouteView.vue'
import defaultSettings from '@/config/defaultSettings';
export const asycRouterMap = [{
	path: '/',
	hidden: true,
	redirect: '/home',
	component: EmptyRouteView,
	children: [{
		name: 'home',
		path: '/home',
		component: () => import('@/views/impromptuQA/doExercise.vue'),
		meta: {
			title: '首页',
		}
	}],
}]
export const constantRouterMap = [{
		path: '/redirect',
		component: BasicLayout,
		hidden: true,
		children: [{
			name: 'redirect',
			path: '/redirect/:path(.*)',
			component: () => import('@/components/redirect.vue')
		}]
	},
	{
		path: '/user',
		component: EmptyRouteView,
		redirect: '/login',
		hidden: true,
		children: [{
				path: 'login',
				name: 'login',
				component: () => import( /* webpackChunkName: "user" */ '@/views/user/Login')
			}

		]
	},

	{
		path: '/404',
		hidden: true,
		component: () =>
			import('@/components/404/index.vue')
	}

]

const router = new Router({
	// mode: 'history',
	base: '/',
	//routes: [...constantRouterMap],
	routes: asycRouterMap.concat([...constantRouterMap]),
	scrollBehavior(to, from, savedPosition) {
		return {
			x: 0,
			y: 0
		}
	}

})

router.afterEach((to, from) => {
	document.title = defaultSettings.title;
})

const originalPush = Router.prototype.push
/* 处理重复点击的问题 */
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}
export default router